let baseUrl = "http://localhost:8091/emos-wx-api"

export const tencent = {
    trtc: {
        appid: "你自己的TRTC的APPID"
    }
}

export const url = {
	register: baseUrl + "/user/register",
	login: baseUrl + "/user/login",
}

export const ajax = (url, method, data, fun) => {
	uni.request({
			"url": url,
			"method": method,
			"header": {
				token: uni.getStorageSync("token")
			},
			"data": data,
			success: function(resp) {
				if (resp.statusCode == 401) {
					uni.redirectTo({
						url: "/pages/login/login.vue"
					})
				} else if (resp.statusCode == 200 && resp.data.code == 200) {
					let data = resp.data
					if (data.hasOwnProperty("token")) {
						let token = data.token
						// console.log(token)
						uni.setStorageSync("token", token)
					}
					fun(resp)
				} else {
					uni.showToast({
						icon: "none",
						title: resp.data.msg
					})
				}
			},
		})
}